package com.freeman.cement.util;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;

import java.util.ArrayList;
import java.util.List;

public class PageHelperForListUtil {
    public static PageInfo getPageInfo(List list, int pageNum, int pageSize) {
        //这里需要PageHelper直接操作list
        Page page = new Page(pageNum, pageSize);
        int total = list.size();
        page.setTotal(total);
        int startIndex = (pageNum - 1) * pageSize;
        int endIndex = Math.min(startIndex + pageSize, total);
        PageInfo pageInfo = null;
        if (startIndex > endIndex) {
            page.addAll(new ArrayList());
            pageInfo = new PageInfo<>(page);
        } else {
            page.addAll(list.subList(startIndex, endIndex));
            pageInfo = new PageInfo<>(page);
        }
        return pageInfo;
    }
}
